<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="signupForm">
							<div class="form-group">	
								<label class="col-sm-2 control-label">评分年度：</label>
								<div class="col-sm-4">
									<input  name="year" readonly="readonly" th:value="${map.year}" class="form-control " type="text" >
								</div>
								<label class="col-sm-2 control-label">评分月度：</label>
								<div class="col-sm-4">
									<input  name="month"  readonly="readonly" th:value="${map.month}" class="form-control " type="text">
								</div>
							</div>
							<div class="form-group" th:each="team :${teamList}">
								<input class="hidden" th:name="'list['+${teamStat.index}+'].id'" th:value="${team.id}"/>
								<label class="col-sm-2 control-label" th:text="${team.teamName}"></label>
								<!-- <div class="col-sm-4">
									<input   th:value="${team.ord}" readonly="readonly" class="form-control ord" type="text" placeholder="排名">
								</div> -->
								<div class="col-sm-10">
									<input th:name="'list['+${teamStat.index}+'].score'"  required th:value="${team.score}"  class="form-control score" type="text" placeholder="评分">
									<span class="msg" style="color: red"></span>
								</div>
								<!-- <div >
									<span id="msg"></span>
								</div> -->
								<!-- <div class="col-sm-4">
									<input name="deptId" class="form-control" type="text">
								</div> -->
							</div>
							<div class="form-group">
								<div class="col-sm-12 col-sm-offset-5">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>	
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/appjs/per/team/edit.js">
	</script>
	<script>
		$(function(){
			var sv;
			var ave = 0;
			$('.score').focus(function(){
				sv= $(this).val();
			})
			$('.score').change(function(){
				
				var val=$(this).val();
				console.log(val)
				var reg = /^100(\.00)?$|^(\d|[1-9]\d)(\.\d{1,2})?$/;
				//alert(!reg.test(val))
				if(!reg.test(val)){
					layer.alert("请输入0-100的数值")
					$(this).val(sv);
					return false;
				}
				
				$('.msg').html("");
				var num = 0;
				var sum = 0;
				
				$('.score').each(function(){
					var score = $.trim($(this).val());
					//console.log(score)
					if(score != '' && score != 'undefined' && score != null){
						num++;
						sum += parseFloat(score);
					}
				})
				ave = (sum/num).toFixed(2);
				 
				var v = (num+1)*90-sum;
				var v2 = (num)*90- (sum-$(this).val())
				$(this).next().html("当前均分  "+ave+", 还需评分  "+v+",或将当前评分改为  "+v2)
				//v+sum/num++ = 90
				//layer.msg("当前均分为"+ave+",下一个人的评分为"+v+"则可以满足平均分为90分");
			})
		})
		
		function getScore (ord){
			return 100-ord+1;
		}
		
		function update() {
			 var num = 0;
			var sum = 0;
			
			$('.score').each(function(){
				var score = $.trim($(this).val());
				//console.log(score)
				if(score != '' && score != 'undefined' && score != null){
					num++;
					sum += parseFloat(score);
				}
			})
			ave = (sum/num).toFixed(2);
			if(ave != 90){
				layer.alert("请确保所有人的平均分为90分")
				return;
			} 
			$.ajax({
				cache : true,
				type : "POST",
				url : "/per/team/updateScore",
				data : $('#signupForm').serialize(),// 你的formid
				async : false,
				error : function(request) {
					parent.layer.alert("Connection error");
				},
				success : function(data) {
					if (data.code == 0) {
						location.href="/tips/success"

					} else {
						location.href="/tips/fail"
					}

				}
			});

		}
	</script>
</body>

</html>
